package cn.edu.scau.cmi.youbaiquan.controller;

import java.net.URL;
import java.util.ResourceBundle;

import cn.edu.scau.cmi.youbaiquan.abstractFactory.domainAbstractClass.AbstractInsurance;
import cn.edu.scau.cmi.youbaiquan.abstractFactory.factory.AbstractInsuranceFactory;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.TextArea;

public class AbstractFactoryController {

    @FXML
    private ResourceBundle resources;

    @FXML
    private URL location;

    @FXML
    private ChoiceBox<String> choice_insurance;

    @FXML
    private Button btn_showinsurance;

    @FXML
    private ChoiceBox<String> choice_company;

    @FXML
    private TextArea tv_result;

    @FXML
    void displayMessage(ActionEvent event) {
        // (1) 选择保险公司
        String companyKind = choice_company.getValue();
        AbstractInsuranceFactory factory = AbstractInsuranceFactory.getFactory(companyKind);

        // (2)选择产品
        String insuranceKind = choice_insurance.getValue();
        AbstractInsurance insurance = null;
        switch (insuranceKind) {
            case "身体受伤":
                insurance = factory.getBodyInjureInsurance();
                break;
            case "汽车损坏":
                insurance = factory.getCarDamageInsurance();
                break;
            case "人员伤亡":
                insurance = factory.getCasualtiesInsurance();
                break;
            case "多种事故":
                insurance = factory.getAccidentsInsurance();
                break;
        }
        if (insurance != null) {
            tv_result.setText(insurance.showInsurance());
        }
    }

    @FXML
    void initialize() {
        assert choice_insurance != null : "fx:id=\"choice_insurance\" was not injected: check your FXML file 'AbstractFactoryUI.fxml'.";
        assert btn_showinsurance != null : "fx:id=\"btn_showinsurance\" was not injected: check your FXML file 'AbstractFactoryUI.fxml'.";
        assert choice_company != null : "fx:id=\"choice_company\" was not injected: check your FXML file 'AbstractFactoryUI.fxml'.";
        assert tv_result != null : "fx:id=\"tv_result\" was not injected: check your FXML file 'AbstractFactoryUI.fxml'.";
        
        ObservableList<String> companyOptions = FXCollections.observableArrayList("中国人寿保险", "平安保险");
        choice_company.setValue("中国人寿保险");
        choice_company.setItems(companyOptions);
        ObservableList<String> insuranceOptions = FXCollections.observableArrayList("身体受伤", "汽车损坏", "人员伤亡", "多种事故");
        choice_insurance.setValue("身体受伤");
        choice_insurance.setItems(insuranceOptions);

    }
}
